package com.botann.projects.controller;

import com.botann.projects.base.BaseController;
import com.botann.projects.base.Model;
import com.botann.projects.constants.API;
import com.botann.projects.constants.Constant;
import com.botann.projects.service.VersionServiceIntf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * projects
 * VersionController
 * Created by 刘山国 on 2020/5/12.
 * Copyright (c) 2017 伯坦科技. All rights reserved
 */
@RestController
public class VersionController extends BaseController {
    @Override
    public Class loggerClass() {
        return VersionController.class;
    }

    @Autowired
    private VersionServiceIntf service;

    /*
     * 添加更新项目
     * @param roleJson String
     * @return Model
     */
    @RequestMapping(value = API.URL_VERSION_ADD_UPDATE, method = RequestMethod.POST)
    public Model addRole(@RequestParam String json) {
        try {
            service.addOrUpdate(json);
            return successModel(Constant.DO_SUCCESS);
        } catch (Exception e) {
            return failureModel(e);
        }
    }

    @RequestMapping(value = API.URL_VERSIONS, method = RequestMethod.POST)
    public Model projects(Integer pageIndex, Integer pageSize) {
        try {
            return successModel(service.loadVersions(pageIndex,pageSize));
        } catch (Exception e) {
            return failureModel(e);
        }
    }
}
